<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    :destroyOnClose="true"
    :maskClosable="false"
    cancelText="关闭"
  >
    <ProjectBuild id="projectForm" ref="projectForm" :printModel="print" :dataId="dataId" :editable="editable"  v-model="projectData"></ProjectBuild>
    <div slot="footer">
      <a-button key="cancel" @click="handleCancel">
        关闭
      </a-button>
      <!-- <a-button v-if="!editable" key="print" v-print="'#projectForm'">
        导出pdf
      </a-button> -->
      <template v-if="editable">
        <a-button v-if="!actStatus" key="save" type="primary" :disabled="savetting" :loading="savetting" @click="handleSave(actStatus)">
          保存草稿
        </a-button>
        <a-button key="submit" type="primary" @click="handleOk" :disabled="submitting" :loading="submitting">
          保存并提交
        </a-button>
      </template>
    </div>
  </a-modal>
</template>

<script>
import ProjectBuild from './ProjectBuild'
import XSelectUserByDep from '@/components/extends/XSelectUserByDep'
import { setProject } from '@/api/api'
import moment from 'moment'
export default {
  name:'ProjectModal',
  components: {
    ProjectBuild,
    XSelectUserByDep
  },
  data() {
    return {
      title: '项目申报',
      width: 1000,
      dataId:'',
      visible: false,
      confirmLoading: false,
      print:false,
      editable:true,
      disableSubmit: true,
      submitting:false,
      savetting:false,
      actStatus:'',
      model: {},
      projectData: {},
      workflowModel: {
        handlerId: '',
        operation: 'start'
      },
      url: {
        config: '/bizConfig/list'
      },
      successTxt:''
    }
  },
  methods: {
    add () {
        this.title = '添加'
        this.visible = true
        this.actStatus = 10
        this.$nextTick(()=>{
          this.$refs.projectForm.add({
            researchProject:{
              actStatus:10
            }
          })
        })
    },
    apply(data){
        this.title = '项目申请'
        this.visible = true
        this.$nextTick(()=>{
          this.$refs.projectForm.apply(data)
        })
    },
    edit (record) {
        this.title = '编辑'
        this.projectData = record
        this.dataId =record.id
        this.visible=true
    },
    preview (record) {
        this.title = '查看'
        this.visible = true
        // this.projectData = record
        this.editable = false
        this.print = true
        this.dataId =record.id
        this.disableSubmit = true
    },
    close () {
        this.title = ''
        this.dataId = ''
        this.editable = true
        this.print = false
        this.actStatus = ''
        this.projectData = {}
        this.disableSubmit = false
        this.visible = false;
        this.$emit('close');
    },
    handlePrintPDF(){
      this.getPdf('projectForm','广东培正学院学生科研项目立项申报书')
    },
    handleOk(flag) {
      if(!this.submitting){
        this.submitting = true
        this.$refs.projectForm.submitForm(false).then(res=>{
          this.visible = false
          this.$emit('ok')
        }).finally(()=>{
          this.submitting = false
        })
      }
    },
    handleSave(flag) {
      if(flag&&!this.savetting){
        this.savetting = true
        this.$refs.projectForm.submitForm(true).then(res=>{
          this.visible = false
          this.$emit('ok')
        }).finally(()=>{
          this.savetting = false
        })
      }else{
        this.$refs.projectForm.saveForm().then(res=>{
          this.visible = false
          this.$emit('ok')
        })
      }
      

    },
    handleCancel() {
      this.close()
    },
    onCellChange() {}
  }
}
</script>

<style scoped>
#staffLeaveTable .input .ant-input,
.staffLeaveTableId .ant-input {
  border: 0 solid #000 !important;
  border-radius: 0;
  display: inherit;
  background-color: #fff;
}
</style>
